#!/bin/bash

LANGUAGE_DAT="etc/texmf/tex/generic/config/language.dat"
LANGUAGE_DAT_LUA="etc/texmf/tex/generic/config/language.dat.lua"
LANGUAGE_DEF="etc/texmf/tex/generic/config/language.def"

shopt -s nullglob

cp usr/share/texmf-dist/tex/generic/config/language.us $LANGUAGE_DAT
for file in var/lib/texmf/arch/installedpkgs/*.dat; do
    echo >> $LANGUAGE_DAT
    echo "% $file" >> $LANGUAGE_DAT
    cat $file >> $LANGUAGE_DAT
done

cp usr/share/texmf-dist/tex/generic/config/language.us.lua $LANGUAGE_DAT_LUA
for file in var/lib/texmf/arch/installedpkgs/*.dat.lua; do
    echo >> $LANGUAGE_DAT_LUA
    echo "-- $file" >> $LANGUAGE_DAT_LUA
    cat $file >> $LANGUAGE_DAT_LUA
done
echo "}" >> $LANGUAGE_DAT_LUA

cp usr/share/texmf-dist/tex/generic/config/language.us.def $LANGUAGE_DEF
for file in var/lib/texmf/arch/installedpkgs/*.def; do
    echo >> $LANGUAGE_DEF
    echo "% $file" >> $LANGUAGE_DEF
    cat $file >> $LANGUAGE_DEF
done
echo "\uselanguage {USenglish} %%% This MUST be the last line of the file." >> $LANGUAGE_DEF
